package com.news.gpb.dao;

import com.news.gpb.entity.News;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface NewsDao {

    @Select("select * from news where news_tag =#{news.news_tag} limit 4")
    List<News> getNewsList(@Param("news") News news);

    @Select("select * from news where news_tag =#{news.news_tag}")
    List<News> getAllList(@Param("news")News news);

    @Select("select * from news limit 10")
    List<News> getHotList();

    @Select("select * from news where news_id=#{news_id}")
    News getNewsDetail(@Param("news_id") int news_id);

    @Update("update news set news_comments =news_comments+1 where news_id=#{news_id}")
    Integer updateCommentCount(@Param("news_id") int news_id);

    @Select("select * from news where news_title like '%${keyword}%' or news_content like '%${keyword}%' or news_author like '%${keyword}%'")
    List<News> search(@Param("keyword") String keyword);

    @Update("update news set news_views =news_views+1 where news_id=#{news.news_id}")
    Integer updateViews(@Param("news") News news);

    @Update("update news set news_likes =news_likes+1 where news_id=#{news_id}")
    Integer updateLikesUp(@Param("news_id") int news_id);

    @Update("update news set news_likes =news_likes-1 where news_id=#{news_id}")
    Integer updateLikesDown(@Param("news_id") int news_id);

    @Update("update news set news_collect =news_collect+1 where news_id=#{news_id}")
    Integer updateCollectUp(@Param("news_id") int news_id);

    @Update("update news set news_collect =news_collect-1 where news_id=#{news_id}")
    Integer updateCollectDown(@Param("news_id") int news_id);

    @Select("select * from news where news_id=#{news_id}")
    News getNewsById(@Param("news_id")int news_id);
}
